package com.zzyl.nursing.task;

import cn.hutool.core.collection.CollUtil;
import com.zzyl.nursing.domain.Elder;
import com.zzyl.nursing.service.IElderService;
import com.zzyl.nursing.service.INursingTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 定时生成月度护理任务
 */
@Component
@Slf4j
public class GenerateNursingTaskJob {
    @Autowired
    private IElderService elderService;

    @Autowired
    private INursingTaskService nursingTaskService;

    public void generateNursingTask() {
        // 查询所有老人
        List<Elder> elderList = elderService.lambdaQuery().eq(Elder::getStatus, 1).list();
        if(CollUtil.isEmpty(elderList)){
            log.error("护理老人为空");
            return;
        }
        elderList.forEach(elder -> nursingTaskService.generateMonthlyTask(elder));
        log.info("生成月任务成功");
    }
}